import axiosInstance from "../../plugins/axios";
import { ElMessage } from "element-plus";
import { InvitationDTO } from "../../type/Invitation";

// 获取邀请详情
export const getInvitationDetails = async (token: string) => {
  const res =await axiosInstance.post(`/invitations/details?token=${token}`);
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "获取邀请信息失败");
    throw new Error(res.data.message || "获取邀请信息失败");
  }
};

// 接受邀请
export const acceptInvitationMethod = async (token: string) => {
  const res =await axiosInstance.post(`/invitations/accept?token=${token}`);
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "获取邀请信息失败");
    throw new Error(res.data.message || "获取邀请信息失败");
  }
};

// 拒绝邀请
export const rejectInvitationMethod = async (token: string) => {
  const res =await axiosInstance.post(`/invitations/reject?token=${token}`);
  if (res.data.code == 1) {
    return res.data.data; // 返回数据
  } else {
    ElMessage.error(res.data.message || "获取邀请信息失败");
    throw new Error(res.data.message || "获取邀请信息失败");
  }
};
